package cn.tedu.demo.service.tools;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class TimeSetter {

    public static LocalDateTime timeSetter() {
        StringBuilder builder = new StringBuilder();
        LocalDateTime localDateTime = LocalDateTime.now();
        int year = localDateTime.getYear();
        int month = localDateTime.getMonthValue();
        int day = localDateTime.getDayOfMonth();
        int hour = localDateTime.getHour();
        int minute = localDateTime.getMinute();
        int second = localDateTime.getSecond();
        builder.append(year);
        builder.append("-");
        String monthString = String.valueOf(month);
        builder.append(monthString = (monthString.length() > 1) ? (monthString = monthString) : (monthString = 0 + monthString));
        builder.append("-");
        builder.append(day);
        builder.append(" ");
        builder.append(hour);
        builder.append(":");
        builder.append(minute);
        builder.append(":");
        String secondString = String.valueOf(second);
        builder.append(secondString = (secondString.length() > 1) ? (secondString = secondString) : (secondString = 0 + secondString));
        String time = builder.toString();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime currentTime = LocalDateTime.parse(time, dateTimeFormatter);
        return currentTime;
    }

}